package main

import (
	"fmt"
	"github.com/garyburd/redigo/redis"
)

func main() {
	// 通过go向redis写入数据和读取数据
	// 1. 连接到redis
	conn, err1 := redis.Dial("tcp", "192.168.57.133:6379")
	if err1 != nil {
		fmt.Println("redis.Dial err =", err1)
		return
	}
	defer conn.Close()

	// 2. 通过go向redis写入数据  
	conn.Do("HSet", "user01", "name", "john")
	conn.Do("HSet", "user01", "age", 18)

	r, _ := redis.String(conn.Do("HGet", "user01", "name"))
	r2, _ := redis.Int(conn.Do("HGet", "user01", "age"))
	fmt.Println("name的值为:", r)
	fmt.Println("name的值为:", r2)

	fmt.Println("操作成功")
}